import echo from './service';

type EchoServer impl(echo::Service) {
    verbose: Bool
};

method EchoServer.echo: rpc::Method[echo::Request, echo::Response]
    &(this) => &(req) =>
        if this.verbose:
            { yield { |echo::Response| {
                content: { "Reply: ?" req.content }
            } } },
        else:
            { yield { |echo::Response| {
                content: req.content
            } } };
do
    { rpc::serve {
        service: echo::Service,
        backend: echo::DefaultServerBackend,
        options: {},
        constructor: &(arg,_) =>
            { yield { |echo::Service| { |EchoServer| {
                verbose: arg.verbose
            } } } }
    } }
    . { crash-on-error };
